package ru.ntcreb.csir.libs.methods.SVCH;

import java.util.Map;

import ru.ntcreb.csir.libs.methods.SVCH.dto.TractDTO;
import ru.ntcreb.csir.libs.methods.SVCH.xml.XMLBuilderService;
import ru.ntcreb.csir.libs.methods.SVCH.xml.XMLParserService;

public class TractService {

	// TODO refactor :properties?
	private final static String path = "D:\\methodics\\PuzzleSvch.dll";

	private final static String path1 = "C:\\Users\\Random111\\workspace_mine"
			+ "\\MicrowavesProject\\PuzzleSvch\\x64\\Release\\PuzzleSvch.dll";
	static {
		System.load(path1);
	}

	private final XMLParserService parserService = new XMLParserService();
	private final XMLBuilderService builderService = new XMLBuilderService();

	public TractDTO createTractDTO(double approximationCoefficient_K,
			double approximationCoefficient_N, double voltage_U0,
			double stepness_S) {
		TractDTO tract = new TractDTO();
		tract.setApproximationCoefficient_K(approximationCoefficient_K);
		tract.setApproximationCoefficient_N(approximationCoefficient_N);
		tract.setStepness_S(stepness_S);
		tract.setVoltage_U0(voltage_U0);
		return tract;
	}

	public native String createTractArrayXML(String tract);

	public Map<Double, Double> createTractArray(TractDTO tract) {

		TractDTO[] tractArr = { tract };
		String inputTractXML = builderService.createTractInputXML(tractArr);
		String xml = createTractArrayXML(inputTractXML);
		return parserService.parseTractArray(xml);
	}

	public native String createConsistentTwoTractsArrayXML(String inputTractXML);

	public Map<Double, Double> createConsistentTwoTractsArray(TractDTO tract1,
			TractDTO tract2) {

		TractDTO[] tractArr = { tract1, tract2 };
		String inputTractXML = builderService.createTractInputXML(tractArr);
		String xml = createConsistentTwoTractsArrayXML(inputTractXML);
		return parserService.parseComprehensiveTractArray(xml);
	}

	public native String createParallelTwoTractsArrayXML(String inputTractXML);

	public Map<Double, Double> createParallelTwoTractsArray(TractDTO tract1,
			TractDTO tract2) {

		TractDTO[] tractArr = { tract1, tract2 };
		String inputTractXML = builderService.createTractInputXML(tractArr);
		String xml = createParallelTwoTractsArrayXML(inputTractXML);
		return parserService.parseTractArray(xml);
	}

}
